<template>
	<view v-if="is_init">
		<uni-popup-input name="新增/编辑" @close="on_close">

			<view class="banmi_input_edit a-c">
				<view class="banmi_input_edit_name">
					上级菜单(不选则为1级分类)
				</view>
				<view class="banmi_input_val" v-if="list.length>0">
					<uni-data-select-tree v-model="category_name" main_id="id" association_id='superior_id'
						:parent_id="find.superior_id" :placeholder="category_name" :localdata="list"
						@change="change_category_id"></uni-data-select-tree>
				</view>
			</view>
			<view class="banmi_input_edit a-c">
				<view class="banmi_input_edit_name">
					<text class="cred">*</text>名称
				</view>
				<view class="banmi_input_val">
					<uni-easyinput v-model="find.name" placeholder="请输入name">
					</uni-easyinput>
				</view>
			</view>
			<view class="banmi_input_edit a-c">
				<view class="banmi_input_edit_name">
					<text class="cred">*</text>用户发布支付金额(元)
				</view>
				<view class="banmi_input_val">
					<uni-easyinput v-model="find.article_pay_money" type="number" placeholder="请输入金额">
					</uni-easyinput>
					<view class="banmi_input_val p-t-10 f-14 c-7">
						默认0元则用户可免费发布(这里价格优先级最高)
					</view>
				</view>
			</view>
			<view class="banmi_input_edit a-c">
				<view class="banmi_input_edit_name">
					<text class="cred">*</text>用户刷新文章多少钱每次(元)
				</view>
				<view class="banmi_input_val">
					<uni-easyinput v-model="find.article_refresh_pay_money" type="number" placeholder="请输入金额">
					</uni-easyinput>
					<view class="banmi_input_val p-t-10 f-14 c-7">
						默认0元则用户可免费发布(这里价格优先级最高)
					</view>
				</view>
			</view>


			<view class="banmi_input_edit a-c">
				<view class="banmi_input_edit_name">
					<text class="cred">*</text>图标
				</view>
				<view class="banmi_input_val">
					<upImg ref="upimg" :val='1' name="图片" :count="1" :list="find.icon" t_type="images"
						@confirm="confirm_icon">
					</upImg>
				</view>
			</view>
			<view class="banmi_input_edit banmi_flex a-c">
				<view class="banmi_input_edit_name">
					是否上架
				</view>
				<view @click="confirm_open(find.open)">
					<banmi-switch :is_state="find.open" is_type='1'></banmi-switch>
				</view>
			</view>


			<view class="a-c  p-b-20 banmi_input_edit">
				<view class="banmi_input_edit_name">
				</view>
				<view class="">
					<button @click="on_sava()" type="primary" style="width: 80px;" size="mini">保存</button>
				</view>
			</view>

		</uni-popup-input>
		<!-- 	颜色选择器 -->
		<t-color-picker ref="colorPicker" @confirm="confirm_color"></t-color-picker>
	</view>
</template>

<script>
	import {
		getParents,
		patTree,
		getSortMenu,
		onqueryload
	} from '@/common/bmupload/recursion.js'
	import provinceData from '@/components/fd-picker/city-china.json';
	var find = {
		category_id: '',
		name: '',
		icon: '',
		creation_time: '',
		open: 2,
		status: '',
		userip: '',

	};
	export default {
		components: {},
		props: {

		},
		data() {
			return {
				find: {},
				category_name: '选择分类',
				list: [],
				is_init: false,
				nav_list: [],
				img_url: '',
				arr_val: [{
						"value": '1',
						"text": "按钮1",
					},
					{
						"value": "2",
						"text": "按钮2",
					},
					{
						"value": "3",
						"text": "按钮3",
					},
				],
				provinceData: provinceData, //本地省市区数据 
				screenWidth: 0,

			}
		},

		methods: {
			change_category_id(name, item) {
				this.category_name = name
				this.find.superior_id = item.id



			},
			init(id, list) {
				this.list = list


				this.init_find(id);

			},
			init_find(id) {
				var that = this;
				that.id = id
				 
				this.category_name = '请选择分类';
				if (that.id == 0) {
					this.find = {
						category_id: '',
						name: '',
						icon: '',
						creation_time: '',
						open: 2,
						status: '',
						userip: '',
					
					};
					this.is_init = true;
					return
				}
				let requestParams = {
					id: that.id,
				};
				this.Http.post('banmichaoqiangbizhi/admin/Articlecategory/views', requestParams).then(ret => {
					if (ret.status == 200) {
						this.find = ret.data.find;

						for (var i = 0; i < that.list.length; i++) {
							if (that.list[i]['id'] == that.find.superior_id) {
								that.category_name = that.list[i]['name'];
							}
						}
						setTimeout(function() {
							that.is_init = true;
						}, 100);
						return
					}
					uni.showToast({
						title: ret.msg,
						duration: 2000,
						icon: 'error'
					});
				})
			},
			confirm_icon(vals) {
				if (vals.length == 0) {
					this.find.icon = ''
					return
				}
				this.find.icon = vals[0]['attachment']
			},
			confirm_open(val) {
				if (val == 2) {
					this.find.open = 1
					return
				}
				this.find.open = 2
			},
			on_sava() {
				var that = this;
				this.find.id = this.id
				this.Http.post('banmichaoqiangbizhi/admin/Articlecategory/edit', this.find).then(ret => {
					uni.showToast({
						title: ret.msg,
						icon: 'none'
					})
					if (ret.status == 200) {
						this.$emit("confirm");
						this.on_close();
					}
				})
			},


			on_close() {
				this.category_name = '';
				this.is_init = false;
			},
			//js分类方法

		}
	}
</script>

<style>
	button::after {
		border: none;
	}

	.top_head {
		background-color: #F8F8F8;
		width: 100%;
		top: 0;
		left: 0;
		z-index: 999;
		position: sticky
	}

	.but {
		width: 120rpx;
		height: 100rpx;
		padding: 0;
		border: 0;
		background-color: transparent;
		outline: none;
	}
</style>